/**
 * Copyright  (c) 2009-2013 XLab,  Org. 
 * All  rights  reserved. 
 */
package org.xlab.baseframework.domain.view;

import java.text.SimpleDateFormat;
import java.util.Set;

import org.springframework.beans.BeanUtils;
import org.xlab.baseframework.domain.SystemCode;
import org.xlab.baseframework.domain.enumerate.EnumDeletedIndentifying;
import org.xlab.baseframework.system.Declare;

/**
 * <p>
 * 系统编码实体的只读实体
 * </p>
 * 
 * @author MaKuBEX Email:makubexnet@gmail.com
 * @version 1.0.0 Sep 8, 2010
 * @since 1.0.0
 * 
 */
public class SystemCodeVO extends
		AbstractNormalVersionControlViewObject<SystemCode> {

	public static final String FIELD_ID = "id";
	public static final String FIELD_CODE = "code";
	public static final String FIELD_CATEGORY = "category";
	public static final String FIELD_DESCRIPTION = "description";
	public static final String FIELD_SEQUENCE = "sequence";
	public static final String FIELD_DELETEDIND = "deletedInd";
	public static final String FIELD_DELETED = "deleted";
	public static final String FIELD_S_CATEGORY = "s_category";
	public static final String FIELD_CREATED_BY_NAME = "createdByName";
	public static final String FIELD_LASTUPDATED_BY_NAME = "lastUpdatedByName";

	/**
	 * @serialField
	 */
	private static final long serialVersionUID = 769631208303204654L;

	private Long id;
	private String code;
	private SystemCodeVO category;
	private String description;
	private Long sequence;
	private EnumDeletedIndentifying deletedInd;
	private String createdByName;
	private String lastUpdatedByName;

	private Set<SystemCode> subCodes;

	private boolean deleted;
	private String s_category;

	/**
	 * <p>
	 * 空构造函数
	 * </p>
	 */
	public SystemCodeVO() {
		super();
	}

	/**
	 * <p>
	 * 默认构造函数
	 * </p>
	 * 
	 * @param pojo
	 *            普通实体类
	 */
	public SystemCodeVO(SystemCode pojo) {
		BeanUtils.copyProperties(pojo, this, new String[] { FIELD_CATEGORY });
		if (pojo.getCategory() != null) {
			this.category = new SystemCodeVO(pojo.getCategory());
			this.s_category = this.category.getCode();
		} else {
			this.category = null;
			this.s_category = "";
		}
		SimpleDateFormat sdf = new SimpleDateFormat(
				Declare.SYSTEM_LONG_DATE_FORMAT + Declare.SPACE
						+ Declare.SYSTEM_LONG_TIME_FORMAT);
		this.s_createdTime = sdf.format(pojo.getCreatedTime());
		this.s_lastUpdatedTime = sdf.format(pojo.getLastUpdatedTime());
		if (EnumDeletedIndentifying.Y.equals(pojo.getDeletedInd())) {
			this.deleted = true;
		} else {
			this.deleted = false;
		}
	}

	/**
	 * @return the category
	 */
	public SystemCodeVO getCategory() {
		return category;
	}

	/**
	 * @return the code
	 */
	public String getCode() {
		return code;
	}

	/**
	 * @return the createdByName
	 */
	public String getCreatedByName() {
		return createdByName;
	}

	/**
	 * @return the deletedInd
	 */
	public EnumDeletedIndentifying getDeletedInd() {
		return deletedInd;
	}

	/**
	 * @return the description
	 */
	public String getDescription() {
		return description;
	}

	/**
	 * @return the id
	 */
	public Long getId() {
		return id;
	}

	/**
	 * @return the lastUpdatedByName
	 */
	public String getLastUpdatedByName() {
		return lastUpdatedByName;
	}

	/**
	 * @return the s_category
	 */
	public String getS_category() {
		return s_category;
	}

	/**
	 * @return the s_createdTime
	 */
	public String getS_createdTime() {
		return s_createdTime;
	}

	/**
	 * @return the s_lastUpdatedTime
	 */
	public String getS_lastUpdatedTime() {
		return s_lastUpdatedTime;
	}

	/**
	 * @return the sequence
	 */
	public Long getSequence() {
		return sequence;
	}

	/**
	 * @return the subCodes
	 */
	public Set<SystemCode> getSubCodes() {
		return subCodes;
	}

	/**
	 * @return the deleted
	 */
	public boolean isDeleted() {
		return deleted;
	}

	/**
	 * @param category
	 *            the category to set
	 */
	public void setCategory(SystemCodeVO category) {
		this.category = category;
	}

	/**
	 * @param code
	 *            the code to set
	 */
	public void setCode(String code) {
		this.code = code;
	}

	/**
	 * @param createdByName
	 *            the createdByName to set
	 */
	public void setCreatedByName(String createdByName) {
		this.createdByName = createdByName;
	}

	/**
	 * @param deleted
	 *            the deleted to set
	 */
	public void setDeleted(boolean deleted) {
		this.deleted = deleted;
	}

	/**
	 * @param deletedInd
	 *            the deletedInd to set
	 */
	public void setDeletedInd(EnumDeletedIndentifying deletedInd) {
		this.deletedInd = deletedInd;
	}

	/**
	 * @param description
	 *            the description to set
	 */
	public void setDescription(String description) {
		this.description = description;
	}

	/**
	 * @param id
	 *            the id to set
	 */
	public void setId(Long id) {
		this.id = id;
	}

	/**
	 * @param lastUpdatedByName
	 *            the lastUpdatedByName to set
	 */
	public void setLastUpdatedByName(String lastUpdatedByName) {
		this.lastUpdatedByName = lastUpdatedByName;
	}

	/**
	 * @param sequence
	 *            the sequence to set
	 */
	public void setSequence(Long sequence) {
		this.sequence = sequence;
	}

	/**
	 * @see java.lang.Object#hashCode()
	 */
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((code == null) ? 0 : code.hashCode());
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		return result;
	}

	/**
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		SystemCodeVO other = (SystemCodeVO) obj;
		if (code == null) {
			if (other.code != null)
				return false;
		} else if (!code.equals(other.code))
			return false;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		return true;
	}
}
